home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmigaPlus / Tools / Development / renderlib40 / src / rnd_diversity.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-01-13  |  2.6 KB  |  114 lines

  1.  
  2. #include "lib_init.h"
  3. #include "lib_debug.h"
  4. #include <render/render.h>
  5. #include <proto/utility.h>
  6. #include <proto/exec.h>
  7.  
  8. /************************************************************************** 
  9. **
  10. **    rgbarraydiversity
  11. */
  12.  
  13. LIBAPI LONG RGBArrayDiversityA(ULONG *src, UWORD width, UWORD height, struct TagItem *tags)
  14. {
  15.     LONG D = -1;
  16.     RNDPAL *dstpal = (RNDPAL *) GetTagData(RND_MapEngine, NULL, tags);
  17.     dstpal = (RNDPAL *) GetTagData(RND_Palette, (ULONG) dstpal, tags);
  18.     
  19.     if (src && dstpal && width && height)
  20.     {
  21.         LONG tsw = GetTagData(RND_SourceWidth, width, tags);
  22.         LONG xstep = GetTagData(RND_Interleave, 0, tags) + 1;
  23.         LONG y, x;
  24.         FLOAT DF = 0;
  25.         ULONG rgb1, rgb2;
  26.         LONG dr, dg, db;
  27.         LONG num = 0;
  28.  
  29.         ObtainSemaphore(&dstpal->lock);
  30.         
  31.         if (GetP2Table(dstpal))
  32.         {
  33.             for (y = 0; y < height; ++y)
  34.             {
  35.                 for (x = 0; x < width; x += xstep)
  36.                 {
  37.                     rgb1 = src[x];
  38.                     rgb2 = dstpal->table[P2Lookup(dstpal, rgb1)];
  39.                     dr = ((rgb1 & 0xff0000) >> 16);
  40.                     dr -= (LONG) ((rgb2 & 0xff0000) >> 16);
  41.                     dg = ((rgb1 & 0x00ff00) >> 8);
  42.                     dg -= (LONG) ((rgb2 & 0x00ff00) >> 8);
  43.                     db = (rgb1 & 0x0000ff);
  44.                     db -= (LONG) (rgb2 & 0x0000ff);
  45.                     DF += dr*dr + dg*dg + db*db;
  46.                     num++;
  47.                 }
  48.                 src += tsw;
  49.             }
  50.         }
  51.  
  52.         ReleaseSemaphore(&dstpal->lock);
  53.         
  54.         D = DF / num;
  55.     }
  56.  
  57.     return D;
  58. }
  59.  
  60. /************************************************************************** 
  61. **
  62. **    chunkyarraydiversity
  63. */
  64.  
  65. LIBAPI LONG ChunkyArrayDiversityA(UBYTE *src, RNDPAL *srcpal, UWORD width, UWORD height, struct TagItem *tags)
  66. {
  67.     LONG D = -1;
  68.     RNDPAL *dstpal = (RNDPAL *) GetTagData(RND_MapEngine, NULL, tags);
  69.     dstpal = (RNDPAL *) GetTagData(RND_Palette, (ULONG) dstpal, tags);
  70.     
  71.     if (src && srcpal && dstpal && width && height)
  72.     {
  73.         LONG tsw = GetTagData(RND_SourceWidth, width, tags);
  74.         LONG xstep = GetTagData(RND_Interleave, 0, tags) + 1;
  75.         LONG y, x;
  76.         FLOAT DF = 0;
  77.         ULONG rgb1, rgb2;
  78.         LONG dr, dg, db;
  79.         LONG num = 0;
  80.  
  81.         ObtainSemaphore(&srcpal->lock);
  82.         ObtainSemaphore(&dstpal->lock);
  83.         
  84.         if (GetP2Table(dstpal))
  85.         {
  86.             for (y = 0; y < height; ++y)
  87.             {
  88.                 for (x = 0; x < width; x += xstep)
  89.                 {
  90.                     rgb1 = srcpal->table[src[x]];
  91.                     rgb2 = dstpal->table[P2Lookup(dstpal, rgb1)];
  92.                     dr = ((rgb1 & 0xff0000) >> 16);
  93.                     dr -= (LONG) ((rgb2 & 0xff0000) >> 16);
  94.                     dg = ((rgb1 & 0x00ff00) >> 8);
  95.                     dg -= (LONG) ((rgb2 & 0x00ff00) >> 8);
  96.                     db = (rgb1 & 0x0000ff);
  97.                     db -= (LONG) (rgb2 & 0x0000ff);
  98.                     DF += dr*dr + dg*dg + db*db;
  99.                     num++;
  100.                 }
  101.                 src += tsw;
  102.             }
  103.         }
  104.  
  105.         ReleaseSemaphore(&dstpal->lock);
  106.         ReleaseSemaphore(&srcpal->lock);
  107.         
  108.         D = DF / num;
  109.     }
  110.  
  111.     return D;
  112. }
  113.  
  114.